(define (count-pairs x)
    (define store-pairs `())
    (define (push-pair! pair)
        (set! store-pairs (cons pair store-pairs))
    )
    (define (has-pair? pair pair-list)
        (cond 
            ((null? pair-list) #f)
            ((eq-pair? pair (car pair-list)) #t)
            (else  (has-pair? pair (cdr pair-list)))             
        )    
    )
    (define (eq-pair? a b)
        (eq? a b)
    )
    (define (iter x) 
        (cond 
            ((not (pair? x)) #f)
            ((has-pair? (cdr x) store-pairs) #t)
            (else 
                (begin
                    (push-pair! (cdr x))
                    (iter (cdr x))
                )       
            )
        )
    )
    (iter x)
)



(define (make-cycle x)
    (set-cdr! (last-pair x) x)
    x
)

(define (last-pair x)
    (if (null? x)
        x
        (last-pair (cdr x))
    )
)
(define z (make-cycle (list `a `b `c)))

(display (count-pairs z))
(newline)

(display (count-pairs (list 1 2 3 1 2 3 1)))
(exit)